# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=ucl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.03
pkgrel=2
pkgdesc="Portable lossless data compression library written in ANSI C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.oberhumer.com/opensource/ucl/"
license=('GPL')
source=("https://www.oberhumer.com/opensource/${_realname}/download/${_realname}-${pkgver}.tar.gz"
        "ucl-1.03-autoconf-compat.patch"
        "ucl-1.03-missing-macros.patch"
        "ucl-1.03-no-undefined.patch")
sha256sums=('b865299ffd45d73412293369c9754b07637680e5c826915f097577cd27350348'
            '0cbd00a8383c098f98d5b022fcb4fa8d1448501e00221a223be04be0383bafc0'
            'ed5425536d98e2097488001e6e73d2ed93da65050a6fded62435bec077bc594b'
            '56a110aedab800c0a06cf4fd4dcef8f78691a0d091e2f143a2a8f02cfbb4c172')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  
  rm -f acinclude.m4
  rm -f m4/local.m4
  
  patch -Np1 -i "${srcdir}/ucl-1.03-autoconf-compat.patch"
  patch -Np1 -i "${srcdir}/ucl-1.03-missing-macros.patch"
  patch -Np1 -i "${srcdir}/ucl-1.03-no-undefined.patch"
  
  touch ChangeLog
  WANT_AUTOMAKE=latest autoreconf -fiv
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  CFLAGS+=" -std=gnu90"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
